package com.yowasa.xiuxian.engine.battle.strategy.drop.all;

import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.engine.battle.strategy.BaseSpellStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@BS(name = "终天闭幕曲")
@Order(501)
@Component
public class ZhongTianBiMuQu extends BaseSpellStrategy {
    @Autowired
    private BattleHelper battleHelper;

    @Override
    public ElementEnum getElement() {
        return null;
    }

    @Override
    public void action(UserBattleContent first, UserBattleContent second, BattleContent content) {
        int atk = first.getBattleInfo().getSpell() + first.getBattleInfo().getAtk();
        int def = second.getBattleInfo().getRes() / 2;

        int dmg = battleHelper.calAtk(atk, def) * 2;
        int costMp = first.getBattleInfo().getMp() / 5;
        costMp = Math.max(costMp, 200);
        first.getBattleInfo().setCmp(first.getBattleInfo().getCmp() - costMp);
        battleHelper.autoAction(this, first, second, content, dmg, "终天闭幕曲");
        first.getCd().put("终天闭幕曲", 5);
    }

    @Override
    public void limit(UserBO user) {
        if (user.getStage() < 5) {
            throw new HandlerException("学习/使用终天闭幕曲阶位需要在如曜之金以上");
        }
    }

    @Override
    public String limitDesc() {
        return "学习/使用终天闭幕曲阶位需要在如曜之金以上";
    }

    @Override
    public String desc() {
        return "奏响高天之歌，吹奏送葬的闭幕曲\ncd4回合，消耗20%的MP造成（术法攻击+物理攻击）两倍的法术穿透伤害，无视对方50%的抗性";
    }

    @Override
    public boolean check(UserBattleContent user, BattleContent content) {
        Integer cd = user.getCd().get("终天闭幕曲");
        if (cd != null && cd > 0) {
            return false;
        }
        int costMp = user.getBattleInfo().getMp() / 5;
        costMp = costMp < 200 ? 200 : costMp;
        if (user.getBattleInfo().getCmp() < costMp) {
            return false;
        }
        return true;
    }
}
